package com.ruoyi.hospital.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.audit.HPatientAudit;
import com.ruoyi.hospital.domain.HPatient;
import com.ruoyi.hospital.domain.vo.HSyntheticalVo;
import com.ruoyi.hospital.mapper.HSyntheticalQueryMapper;
import com.ruoyi.hospital.service.IHSyntheticalQueryService;
import com.ruoyi.hospital.service.IHpatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 综合查询serviceimpl
 * @author liz
 * @date 2023-10-18 14:32
 */
@Service
public class HSyntheticalQueryServiceImpl implements IHSyntheticalQueryService {

    @Autowired
    HSyntheticalQueryMapper syntheticalQueryMapper;

    @Autowired
    IHpatientService hpatientService;

    /**
     * 综合查询列表
     * @param hPatient
     * @return
     */
    @Override
    public List<HPatient> selectSyntheticalList(HPatient hPatient) {
        QueryWrapper<HPatient> queryWrapper = new QueryWrapper<>();
        if (StrUtil.isNotBlank(hPatient.getName())) {
            queryWrapper.like("name", hPatient.getName());
        }
        if (StrUtil.isNotBlank(hPatient.getInpatientNo())) {
            queryWrapper.eq("inpatient_no", hPatient.getInpatientNo());
        }
        if (ObjectUtil.isNotEmpty(hPatient.getParams().get("beginTime"))) {
            queryWrapper.ge("effective_e", hPatient.getParams().get("beginTime"));
        }
        if (ObjectUtil.isNotEmpty(hPatient.getParams().get("endTime"))) {
            queryWrapper.le("effective_e", hPatient.getParams().get("endTime"));
        }
        queryWrapper.orderByDesc("effective_e");
        return hpatientService.list(queryWrapper);
    }

    /**
     * 查询详情列表
     * @param userId
     * @return
     */
    @Override
    public List<HPatientAudit> selectDetailList(Long userId) {
        return syntheticalQueryMapper.selectDetailList(userId);
    }
}
